<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: BoardPanel</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.ui</a> ]
    </div>

    <h1>Coverage Summary for Class: BoardPanel (nl.tudelft.jpacman.ui)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">BoardPanel</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 5)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 27)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.ui;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import java.awt.Color;
        <i>4</i>&nbsp;import java.awt.Dimension;
        <i>5</i>&nbsp;import java.awt.Graphics;
        <i>6</i>&nbsp;
        <i>7</i>&nbsp;import javax.swing.JPanel;
        <i>8</i>&nbsp;
        <i>9</i>&nbsp;import nl.tudelft.jpacman.board.Board;
        <i>10</i>&nbsp;import nl.tudelft.jpacman.board.Square;
        <i>11</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>12</i>&nbsp;import nl.tudelft.jpacman.game.Game;
        <i>13</i>&nbsp;
        <i>14</i>&nbsp;/**
        <i>15</i>&nbsp; * Panel displaying a game.
        <i>16</i>&nbsp; *
        <i>17</i>&nbsp; * @author Jeroen Roosen
        <i>18</i>&nbsp; *
        <i>19</i>&nbsp; */
        <b class="nc"><i>20</i>&nbsp;class BoardPanel extends JPanel {</b>
        <i>21</i>&nbsp;
        <i>22</i>&nbsp; /**
        <i>23</i>&nbsp; * Default serialisation ID.
        <i>24</i>&nbsp; */
        <i>25</i>&nbsp; private static final long serialVersionUID = 1L;
        <i>26</i>&nbsp;
        <i>27</i>&nbsp; /**
        <i>28</i>&nbsp; * The background colour of the board.
        <i>29</i>&nbsp; */
        <b class="nc"><i>30</i>&nbsp; private static final Color BACKGROUND_COLOR = Color.BLACK;</b>
        <i>31</i>&nbsp;
        <i>32</i>&nbsp; /**
        <i>33</i>&nbsp; * The size (in pixels) of a square on the board. The initial size of this
        <i>34</i>&nbsp; * panel will scale to fit a board with square of this size.
        <i>35</i>&nbsp; */
        <i>36</i>&nbsp; private static final int SQUARE_SIZE = 16;
        <i>37</i>&nbsp;
        <i>38</i>&nbsp; /**
        <i>39</i>&nbsp; * The game to display.
        <i>40</i>&nbsp; */
        <i>41</i>&nbsp; private final Game game;
        <i>42</i>&nbsp;
        <i>43</i>&nbsp; /**
        <i>44</i>&nbsp; * Creates a new board panel that will display the provided game.
        <i>45</i>&nbsp; *
        <i>46</i>&nbsp; * @param game
        <i>47</i>&nbsp; * The game to display.
        <i>48</i>&nbsp; */
        <i>49</i>&nbsp; BoardPanel(Game game) {
        <b class="nc"><i>50</i>&nbsp; super();</b>
        <b class="nc"><i>51</i>&nbsp; assert game != null;</b>
        <b class="nc"><i>52</i>&nbsp; this.game = game;</b>
        <i>53</i>&nbsp;
        <b class="nc"><i>54</i>&nbsp; Board board = game.getLevel().getBoard();</b>
        <i>55</i>&nbsp;
        <b class="nc"><i>56</i>&nbsp; int w = board.getWidth() * SQUARE_SIZE;</b>
        <b class="nc"><i>57</i>&nbsp; int h = board.getHeight() * SQUARE_SIZE;</b>
        <i>58</i>&nbsp;
        <b class="nc"><i>59</i>&nbsp; Dimension size = new Dimension(w, h);</b>
        <b class="nc"><i>60</i>&nbsp; setMinimumSize(size);</b>
        <b class="nc"><i>61</i>&nbsp; setPreferredSize(size);</b>
        <i>62</i>&nbsp; }
        <i>63</i>&nbsp;
        <i>64</i>&nbsp; @Override
        <i>65</i>&nbsp; public void paint(Graphics g) {
        <b class="nc"><i>66</i>&nbsp; assert g != null;</b>
        <b class="nc"><i>67</i>&nbsp; render(game.getLevel().getBoard(), g, getSize());</b>
        <i>68</i>&nbsp; }
        <i>69</i>&nbsp;
        <i>70</i>&nbsp; /**
        <i>71</i>&nbsp; * Renders the board on the given graphics context to the given dimensions.
        <i>72</i>&nbsp; *
        <i>73</i>&nbsp; * @param board
        <i>74</i>&nbsp; * The board to render.
        <i>75</i>&nbsp; * @param graphics
        <i>76</i>&nbsp; * The graphics context to draw on.
        <i>77</i>&nbsp; * @param window
        <i>78</i>&nbsp; * The dimensions to scale the rendered board to.
        <i>79</i>&nbsp; */
        <i>80</i>&nbsp; private void render(Board board, Graphics graphics, Dimension window) {
        <b class="nc"><i>81</i>&nbsp; int cellW = window.width / board.getWidth();</b>
        <b class="nc"><i>82</i>&nbsp; int cellH = window.height / board.getHeight();</b>
        <i>83</i>&nbsp;
        <b class="nc"><i>84</i>&nbsp; graphics.setColor(BACKGROUND_COLOR);</b>
        <b class="nc"><i>85</i>&nbsp; graphics.fillRect(0, 0, window.width, window.height);</b>
        <i>86</i>&nbsp;
        <b class="nc"><i>87</i>&nbsp; for (int y = 0; y &lt; board.getHeight(); y++) {</b>
        <b class="nc"><i>88</i>&nbsp; for (int x = 0; x &lt; board.getWidth(); x++) {</b>
        <b class="nc"><i>89</i>&nbsp; int cellX = x * cellW;</b>
        <b class="nc"><i>90</i>&nbsp; int cellY = y * cellH;</b>
        <b class="nc"><i>91</i>&nbsp; Square square = board.squareAt(x, y);</b>
        <b class="nc"><i>92</i>&nbsp; render(square, graphics, cellX, cellY, cellW, cellH);</b>
        <i>93</i>&nbsp; }
        <i>94</i>&nbsp; }
        <i>95</i>&nbsp; }
        <i>96</i>&nbsp;
        <i>97</i>&nbsp; /**
        <i>98</i>&nbsp; * Renders a single square on the given graphics context on the specified
        <i>99</i>&nbsp; * rectangle.
        <i>100</i>&nbsp; *
        <i>101</i>&nbsp; * @param square
        <i>102</i>&nbsp; * The square to render.
        <i>103</i>&nbsp; * @param graphics
        <i>104</i>&nbsp; * The graphics context to draw on.
        <i>105</i>&nbsp; * @param x
        <i>106</i>&nbsp; * The x position to start drawing.
        <i>107</i>&nbsp; * @param y
        <i>108</i>&nbsp; * The y position to start drawing.
        <i>109</i>&nbsp; * @param width
        <i>110</i>&nbsp; * The width of this square (in pixels.)
        <i>111</i>&nbsp; * @param height
        <i>112</i>&nbsp; * The height of this square (in pixels.)
        <i>113</i>&nbsp; */
        <i>114</i>&nbsp; private void render(Square square, Graphics graphics, int x, int y, int width, int height) {
        <b class="nc"><i>115</i>&nbsp; square.getSprite().draw(graphics, x, y, width, height);</b>
        <b class="nc"><i>116</i>&nbsp; for (Unit unit : square.getOccupants()) {</b>
        <b class="nc"><i>117</i>&nbsp; unit.getSprite().draw(graphics, x, y, width, height);</b>
        <b class="nc"><i>118</i>&nbsp; }</b>
        <i>119</i>&nbsp; }
        <i>120</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
